package com.example.blog.controller;

import com.example.blog.base.Result;
import com.example.blog.entity.DictionaryGroup;
import com.example.blog.entity.dto.dictionaryGroup.AddOrUpdateDictGroupDTO;
import com.example.blog.service.DictionaryGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典组模块
 * <p>
 * 字典组表 前端控制器
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/blog/dictionaryGroup")
public class DictionaryGroupController {


    @Autowired
    private DictionaryGroupService dictionaryGroupService;


    /**
     * 新增或修改字典组
     * @param addOrUpdateDictGroupDTO
     * @return
     */
    @PostMapping("/add-or-update")
    public Result<Void> addOrUpdate(@RequestBody @Validated AddOrUpdateDictGroupDTO addOrUpdateDictGroupDTO) {
        dictionaryGroupService.addOrUpdate(addOrUpdateDictGroupDTO);

        return Result.success();
    }

    /**
     * 删除字典组
     * @param id 字典组ID
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Void> del(@PathVariable Long id) {
        dictionaryGroupService.removeById(id);
        return Result.success();
    }


    /**
     * 获取全部的字典组列表
     * @return
     */
    @GetMapping("/list")
    public Result<List<DictionaryGroup>> list() {
        List<DictionaryGroup> list = dictionaryGroupService.list();
        return Result.successData(list);
    }


}
